// 最多线段重合问题
// 测试链接 : https://www.nowcoder.com/practice/1ae8d0b6bb4e4bcdbf64ec491f63fc37
// 测试链接 : https://leetcode.cn/problems/meeting-rooms-ii/

import java.io.*;
import java.util.Arrays;

public class MaxCover {

    //最大数组的个数
    public static int MAX = 10001;

    //public static int[][] line= new int[MAX][2];
    public static int[][] line= {{1,2},{2,3},{1,3}};

    //实际数组的个数
    //public static int n;
    public static int n = 3;
    /*public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        while(in.nextToken() != StreamTokenizer.TT_EOF) {
            int n = (int)in.nval;
            for(int i = 0; i < n; ++i) {
                in.nextToken();
                line[i][0] =(int) in.nval;
                in.nextToken();
                line[i][1] =(int) in.nval;
            }
            //将答案加入到缓冲区
            out.println(compute());
        }
        //将答案整体传送出去
        out.flush();
        out.close();
        br.close();
    }*/

    public static void main(String[] args) {
        int n = compute();
        System.out.println(n);
    }

    public static int compute() {
        //记录答案
        int ans = 0;
        //清空堆
        size = 0;
        //排序有效数组[0-n) 以每个数组第一个位置的数进行升序排序
        Arrays.sort(line,0, n, (a,b) -> a[0] - b[0]);
        for(int i = 0; i < n; ++i) {

            while(size > 0 && heap[0] <= line[i][0]) {
                pop();
            }
            //向小堆中添加数组的末尾元素
            add(line[i][1]);
            ans = Math.max(size,ans);
        }
        return ans;
    }

    //定义一个小根堆
    public static int[] heap = new int[MAX];
    public static int size;
    public static void add(int x) {
        //将添加的元素到堆尾上
        heap[size] = x;
        int child = size;
        ++size;
        //向上建小堆
        while (heap[child] < heap[(child-1) / 2]) {
            swap(child,(child-1)/2);
            child = (child-1)/2;
        }
    }

    public static void pop() {
        //将最小的数交换到堆的末尾
        swap(0,size-1);
        size--;
        //向下调整建堆
        int parent = 0;
        int child = 1;
        while(child < size) {
            child = ((child + 1 < size) && (heap[child+1] < heap[child])) ? child + 1 : child;
            if(heap[parent] > heap[child]) {
                swap(parent,child);
            }
            else {
                break;
            }
            parent = child;
            child = parent * 2 + 1;
        }
    }


    public static void swap(int i, int j) {
        int temp = heap[i];
        heap[i] = heap[j];
        heap[j] = temp;
    }

}
